/*
 * @Autor: Hongting Yuan
 * @Date: 2021-12-02 13:01:53
 * @LastEditors: Ruohong Yu
 * @LastEditTime: 2021-12-23 16:54:23
 * @Description: echarts
 * @FilePath: \mimalld:\桌面\作业\软件工程\前端\front_regit\src\main.js
 */
import Vue from 'vue'
import ElementUI from 'element-ui'
// 导入全局样式
import './assets/css/global.css'
import 'element-ui/lib/theme-chalk/index.css'
import 'element-theme-chalk'
// 浏览器兼容
import 'babel-polyfill'

import axios from 'axios'
import App from './App.vue'
import router from './router'
import store from './store'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import JsonExcel from 'vue-json-excel'
import transition from './assets/js/transition.js'
import crypto from './crypto/crypto'
import preventReClick from './assets/js/preventReClick.js'
import './assets/css/common.css'
import VideoPlayer from 'vue-video-player'
require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts
Vue.use(VideoPlayer)

Vue.prototype.$transition = transition
Vue.component('downloadExcel', JsonExcel)
Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(preventReClick)
Vue.prototype.axios = axios
axios.defaults.baseURL = '/api'
axios.defaults.headers.post['Content-Type'] = 'application/json'

axios.interceptors.request.use(config => {
  NProgress.start()
  return config
}, error => {
  return Promise.reject(error)
})

axios.interceptors.response.use(response => {
  NProgress.done()
  return response
}, error => {
  if (error.response.data.code === 403) {
    this.$router.push('/' + crypto.set(43))
  } else if (error.response.data.code === 404) {
    this.$router.push('/' + crypto.set(44))
  } else if (error.response.data.code === 500) {
    this.$router.push('/' + crypto.set(45))
  } else if (error.response.data.code === 401) {
    window.sessionStorage.clear()
    this.$router.push('/')
    window.location.reload()
  }
  return Promise.reject(error)
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
